/*
 * File     : Performance.java
 * Created  : 2 Jan 2012
 *
 * Copyright © 2011 Matthew Wilson (mj. {my-surname} .uk {at} gmail.com)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.googlecode.dni.test;

import com.googlecode.dni.ByValue;
import com.googlecode.dni.DirectNativeInterface;
import com.googlecode.dni.library.Library;

/**
 * <p>
 *  A manual test to compare the performance of DNI with ordinary (naive) JNI.
 * </p>
 *
 * @author Matthew Wilson
 */
public final class Performance
{

    /**
     *
     * @param args command-line arguments
     */
    public static void main( final String[] args )
    {
        System.loadLibrary( "dnitest" );
        PerfLib lib = DirectNativeInterface.getLibrary( PerfLib.class );

        TestStruct1J s = new TestStruct1J();
        s.x = 10;
        s.y = 20;
        s.p = 3.4;
        s.q = 4.9;
        System.out.println( s );
        System.out.println( s.compute() );
        s.update();
        System.out.println( s );

        TestStruct1D t = TestStruct1D.FACTORY.allocate();
        t.setX( 10 );
        t.setY( 20 );
        t.setP( 3.4 );
        t.setQ( 4.9 );
        System.out.println( t.toDebugString() );
        System.out.println( lib.teststruct1_compute( t ) );
        lib.teststruct1_update( t );
        System.out.println( t.toDebugString() );

    }

    @Library( name = "dnitest", functionPrefix = "performance_" )
    private interface PerfLib
    {
        int teststruct1_compute( @ByValue TestStruct1D v );
        void teststruct1_update( TestStruct1D v );
    }

}
